<template>
  <div class="product-detail">
    <div class="detail-images">
      <div class="images-change">
        <div class="images-big">
          <el-image :src="mainImageUrl" alt="" class="size-full" fit="contain" />
        </div>
        <div class="images-list">
          <div
            class="image-item"
            v-for="(item, index) in imageLists"
            :class="{ selected: selectProductImage.index === index }"
            :key="index"
            @click="switchProductImage(index)"
          >
            <img :src="item?.url" :alt="item?.title" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { computed, reactive } from 'vue'
const props = defineProps({
  imageLists: {
    type: Array as () => ImageList[],
    default: () => {
      return []
    },
  },
})
const selectProductImage = reactive({
  index: 0,
})

const mainImageUrl = computed(() => {
  let src = props.imageLists?.[selectProductImage.index]?.url
  if(src && src.includes('UL120')) {
    return src.replace('UL120', 'UL800')
  }
  return src
})
const switchProductImage = (index: number) => {
  selectProductImage.index = index
}
</script>
<style scoped lang="scss">
.product-detail {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px;
  .detail-images {
    width: 500px;
    margin-right: 40px;
    .images-change {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      .images-big {
        width: 390px;
        height: 390px;
        background: #fff;
        width: 390px;
        height: 390px;
        text-align: center;
        position: relative;
        justify-content: center;
        align-items: center;
        display: flex;
        img {
          max-width: 100%;
          max-height: 100%;
        }
      }
      .images-list {
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        height: 390px;
        padding-right: 10px;
        .image-item {
          width: 60px;
          height: 60px;
          background: #fff;
          text-align: center;
          border: 1px solid transparent;
          margin-bottom: 10px;
          cursor: pointer;
          &.selected {
            border: 1px solid var(--el-color-primary);
          }
          img {
            max-width: 100%;
            max-height: 100%;
            width: 60px;
            height: 60px;
            object-fit: contain;
            display: block;
          }
        }
      }
    }
  }
}
</style>
